/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-27 16:02:34
 * @LastEditTime: 2022-12-26 16:14:04
 */
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'
import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [

      {
        title: '使用人',
        field: 'userName',
        fixed: 'left',

        minWidth: 150,
        slots: {
          header: (params, h) => {
            return table.header.arrow(_this, h, nameOpt.createPeople({
              key: 'userName',
              title: '使用人',
              to: (info) => {
                return {
                  userId: info.userId
                }
              }
            }))
          }
        }
      },
      {
        field: 'userStatusName',
        minWidth: 120,
        header: {
          filter: {
            title: '账号状态',
            key: 'userStatus',
            placeholder: '请选择',
            select: {
              options: [
                { key: 'USING', value: '使用中' },
                { key: 'END', value: '结束' },
              ],
            }
          }
        }
      }, {
        field: 'userPhone',
        minWidth: 130,

        header: {
          filter: {
            title: '绑定手机号',
            key: 'userPhone',
            placeholder: '请输入手机号码',
            input: {}
          }
        }
      }, {
        field: 'phoneX',
        minWidth: 130,
        header: {
          filter: {
            title: '隐私号',
            key: 'phoneX',
            placeholder: '请输入手机号码',
            input: {}
          }
        }
      }, {
        field: 'statusName',
        minWidth: 120,
        title: '隐私号状态',
        header: {
          filter: {
            title: '隐私号状态',
            key: 'status',
            placeholder: '请选择',
            select: {
              options: [
                { key: 'NORMAL', value: '正常' },
                { key: 'ABNORMAL', value: '异常' },
                { key: 'REMOVED', value: '已移除' },
              ]
            }
          }
        }
      },
      {
        title: '剩余天数',
        field: 'endDay',
        minWidth: 100,
      },
      {
        title: '剩余通话时长',
        field: 'talkTime',
        minWidth: 150,
        // slots: {
        //   default: (params, h) => {
        //     return table.cell.text(h, {
        //       value: _this.$dt.tool.formatSeconds(params.row.talkTime)
        //     })
        //   }
        // }


      }, {
        field: 'settingTime',
        minWidth: 180,
        title: '配置时间',
        header: {
          filter: dateOpt.range({
            title: '配置时间',
            startKey: 'settingStartTime',
            endKey: 'settingEndTime',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.settingStartTime, val
                  .settingEndTime).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('配置时间跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.settingStartTime, val
                .settingEndTime).Y >= 2)
            }
          }),
        },
      },

      {
        title: '配置人',
        field: 'settingUserName',
        minWidth: 150,
      },

      {
        title: '操作',
        fixed: 'right',
        width: 380,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: params.row.userStatusName == '使用中' ? '修改隐私号' : '',
              event: params.row.userStatusName == '使用中' ? 'editPackage' : '',
              data: params.row
            })

            btns.push({
              title: '购买记录',
              event: 'buyRecord',
              data: params.row
            })
            btns.push({
              title: '通话记录',
              event: 'callRecord',
              data: params.row
            })
            btns.push({
              title: params.row.userStatusName == '使用中' ? '强制结束' : '',
              event: params.row.userStatusName == '使用中' ? 'endCallSign' : '',
              data: params.row
            })
            btns.push({
              title: '账号动态',
              event: 'dynamic',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }

}

export default Column